﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Portal.Web
{
    [AuthorizeFilterAdminAttribute]
    public class BaseAdminController : BaseController
    {
        private static readonly Type CurrentAdminBaseViewDataKey = typeof(AdminBaseViewData);
        public string CurrentUserName { get { return HttpContext.User.Identity.Name; } }

        /// <summary>
        /// 创建一个返回实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public virtual T CreateAdminViewData<T>() where T : AdminBaseViewData, new()
        {
            var viewData = HttpContext.Items[CurrentAdminBaseViewDataKey] as T;
            if (viewData == null)
            {
                viewData = new T
                {
                    CurrentUserName = CurrentUserName,
                    Culture = Culture
                };
                HttpContext.Items[CurrentAdminBaseViewDataKey] = viewData;
            }
            return viewData;

        }
        public ActionResult NotFount(IResult result)
        {
            if (Request.IsAjaxRequest())
                return Json(result);
            return View(result);
        }

    }
}
